from minio import Minio
from minio.error import S3Error


def main():
    # Create a client with the MinIO server playground, its access key
    # and secret key.
    client = Minio(
        "100.64.139.5:9000",
        access_key="blog",
        secret_key="852179Jial",
        secure=False
    )

    # Make 'blog-image' bucket if not exist.
    found = client.bucket_exists("blog-image")
    if not found:
        client.make_bucket("blog-image")
    else:
        print("Bucket 'blog-image' already exists")

    # Upload '/home/user/Photos/asiaphotos.zip' as object name
    # 'asiaphotos-2015.zip' to bucket 'blog-image'.
    client.fput_object(
        "blog-image", "2023/WechatIMG19.jpeg", "/Users/jl/Downloads/WechatIMG19.jpeg",
    )
    print(
        "'/Users/jl/Downloads/WechatIMG19.jpeg' is successfully uploaded as "
        "object '2023/WechatIMG19.jpeg' to bucket 'blog-image'."
    )


if __name__ == "__main__":
    try:
        main()
    except S3Error as exc:
        print("error occurred.", exc)